#include "RenderingSys/OpenGLDevice.h"
namespace GCRE {
	namespace Rendering {
		COpenGLDevice::COpenGLDevice()
		{

		}

		COpenGLDevice::~COpenGLDevice()
		{

		}

		bool COpenGLDevice::Initialize( const CWindowInfo& winInfo )
		{
			m_hDC = ::GetDC( winInfo.m_hWnd );
			SetupPixelFormat( m_hDC );

			m_hRC = wglCreateContext( m_hDC );
			wglMakeCurrent( m_hDC, m_hRC );
			return true;
		}

		void COpenGLDevice::SetupPixelFormat( HDC hDC )
		{
			int nPixelFormat;
			static PIXELFORMATDESCRIPTOR pfd = {
				sizeof(PIXELFORMATDESCRIPTOR),			// size of this pfd
				1, 
				PFD_DRAW_TO_WINDOW |				// support window
				PFD_SUPPORT_OPENGL |				// support OpenGL
				PFD_DOUBLEBUFFER,					// double buffered
				PFD_TYPE_RGBA,						// RGBA type
				32,									// 32-bit color depth
				0, 0, 0, 0, 0, 0,					// color bits ignored
				0,									// no alpha buffer
				0,									// shift bit ignored
				0,									// no accumulation buff
				0, 0, 0, 0,							// accumulation bits ignored
				32,									// 32-bit z-buffer
				0,									// no stencil buffer
				0,									// no auxiliary buffer
				PFD_MAIN_PLANE,						// main layer
				0,									// reserved
				0, 0, 0								// layer masks ignored
			};
			nPixelFormat = ChoosePixelFormat( hDC, &pfd );
			SetPixelFormat( hDC, nPixelFormat, &pfd );
		}

		void COpenGLDevice::UnInitialize()
		{
			wglMakeCurrent( m_hDC, NULL );
			wglDeleteContext( m_hRC );
		}
	}
}

